﻿
namespace FastFood.Windows.Controles
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using FastFood.Business.Entities;
    using FastFood.Business.Logic;
    using FastFood.Business.Entities.Tipos;

    public partial class ActionBar : UserControl
    {
        #region Parameters

        public byte FormularioID;

        #endregion

        #region Delegate

        public delegate void DelegadoNuevoEventHandler(object sender, EventArgs e);
        public delegate void DelegadoEditarEventHandler(object sender, EventArgs e);
        public delegate void DelegadoEliminarEventHandler(object sender, EventArgs e);
        public delegate void DelegadoGuardarEventHandler(object sender, EventArgs e);
        public delegate void DelegadoCancelarEventHandler(object sender, EventArgs e);
        public delegate void DelegadoImprimirEventHandler(object sender, EventArgs e);

        #endregion

        #region Events

        public event DelegadoNuevoEventHandler EventoNuevo;
        public event DelegadoEditarEventHandler EventoEditar;
        public event DelegadoEliminarEventHandler EventoEliminar;
        public event DelegadoGuardarEventHandler EventoGuardar;
        public event DelegadoCancelarEventHandler EventoCancelar;
        public event DelegadoImprimirEventHandler EventoImprimir;

        #endregion

        #region Virtual

        public virtual void OnEventoNuevo(object sender, EventArgs e)
        {
            if (EventoNuevo != null)
            {
                EventoNuevo(this, e);
            }
        }

        public virtual void OnEventoEditar(object sender, EventArgs e)
        {
            if (EventoEditar != null)
            {
                EventoEditar(this, e);
            }
        }

        public virtual void OnEventoEliminar(object sender, EventArgs e)
        {
            if (EventoEliminar != null)
            {
                EventoEliminar(this, e);
            }
        }

        public virtual void OnEventoGuardar(object sender, EventArgs e)
        {
            if (EventoGuardar != null)
            {
                EventoGuardar(this, e);
            }
        }

        public virtual void OnEventoCancelar(object sender, EventArgs e)
        {
            if (EventoCancelar != null)
            {
                EventoCancelar(this, e);
            }
        }

        public virtual void OnEventoImprimir(object sender, EventArgs e)
        {
            if (EventoImprimir != null)
            {
                EventoImprimir(this, e);
            }
        }

        #endregion

        #region Visible

        public bool VisibleNuevo
        {
            get
            {
                return this.TsbNuevo.Visible;
            }
            set
            {
                this.TsbNuevo.Visible = value;
            }
        }

        public bool VisibleEditar
        {
            get
            {
                return this.TsbEditar.Visible;
            }
            set
            {
                this.TsbEditar.Visible = value;
            }
        }

        public bool VisibleEliminar
        {
            get
            {
                return this.TsbEliminar.Visible;
            }
            set
            {
                this.TsbEliminar.Visible = value;
            }
        }

        public bool VisibleGuardar
        {
            get
            {
                return this.TsbGuardar.Visible;
            }
            set
            {
                this.TsbGuardar.Visible = value;
            }
        }

        public bool VisibleCancelar
        {
            get
            {
                return this.TsbCancelar.Visible;
            }
            set
            {
                this.TsbCancelar.Visible = value;
            }
        }

        public bool VisibleImprimir
        {
            get
            {
                return this.TsbImprimir.Visible;
            }
            set
            {
                this.TsbImprimir.Visible = value;
            }
        }

        #endregion

        #region Text

        public string TextNuevo
        {
            get
            {
                return this.TsbNuevo.Text;
            }
            set
            {
                this.TsbNuevo.Text = value;
            }
        }

        public string TextEditar
        {
            get
            {
                return this.TsbEditar.Text;
            }
            set
            {
                this.TsbEditar.Text = value;
            }
        }

        public string TextGuardar
        {
            get
            {
                return this.TsbGuardar.Text;
            }
            set
            {
                this.TsbGuardar.Text = value;
            }
        }

        public string TextEliminar
        {
            get
            {
                return this.TsbEliminar.Text;
            }
            set
            {
                this.TsbEliminar.Text = value;
            }
        }

        public string TextCancelar
        {
            get
            {
                return this.TsbCancelar.Text;
            }
            set
            {
                this.TsbCancelar.Text = value;
            }
        }

        public string TextImprimir
        {
            get
            {
                return this.TsbImprimir.Text;
            }
            set
            {
                this.TsbImprimir.Text = value;
            }
        }

        #endregion

        #region Enabled

        public bool EnabledNuevo
        {
            get
            {
                return this.TsbNuevo.Enabled;
            }
            set
            {
                this.TsbNuevo.Enabled = value;
            }
        }

        public bool EnabledEditar
        {
            get
            {
                return this.TsbEditar.Enabled;
            }
            set
            {
                this.TsbEditar.Enabled = value;
            }
        }

        public bool EnabledEliminar
        {
            get
            {
                return this.TsbEliminar.Enabled;
            }
            set
            {
                this.TsbEliminar.Enabled = value;
            }
        }

        public bool EnabledGuardar
        {
            get
            {
                return this.TsbGuardar.Enabled;
            }
            set
            {
                this.TsbGuardar.Enabled = value;
            }
        }

        public bool EnabledCancelar
        {
            get
            {
                return this.TsbCancelar.Enabled;
            }
            set
            {
                this.TsbCancelar.Enabled = value;
            }
        }

        public bool EnabledImprimir
        {
            get
            {
                return this.TsbImprimir.Enabled;
            }
            set
            {
                this.TsbImprimir.Enabled = value;
            }
        }

        #endregion

        #region Image

        public Image ImageNuevo
        {
            get
            {
                return this.TsbNuevo.Image;
            }
            set
            {
                this.TsbNuevo.Image = value;
            }
        }

        public Image ImageEditar
        {
            get
            {
                return this.TsbEditar.Image;
            }
            set
            {
                this.TsbEditar.Image = value;
            }
        }

        public Image ImageEliminar
        {
            get
            {
                return this.TsbEliminar.Image;
            }
            set
            {
                this.TsbEliminar.Image = value;
            }
        }

        public Image ImageGuardar
        {
            get
            {
                return this.TsbGuardar.Image;
            }
            set
            {
                this.TsbGuardar.Image = value;
            }
        }

        public Image ImageCancelar
        {
            get
            {
                return this.TsbCancelar.Image;
            }
            set
            {
                this.TsbCancelar.Image = value;
            }
        }

        public Image ImageImprimir
        {
            get
            {
                return this.TsbImprimir.Image;
            }
            set
            {
                this.TsbImprimir.Image = value;
            }
        }

        #endregion

        #region Constructor

        public ActionBar()
        {
            InitializeComponent();
        }

        #endregion

        #region Methods

        private void ActionBar_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {

            }
        }

        private void TsbNuevo_Click(object sender, EventArgs e)
        {
            OnEventoNuevo(sender, e);
        }

        private void TsbEditar_Click(object sender, EventArgs e)
        {
            OnEventoEditar(sender, e);
        }

        private void TsbEliminar_Click(object sender, EventArgs e)
        {
            OnEventoEliminar(sender, e);
        }

        private void TsbGuardar_Click(object sender, EventArgs e)
        {
            OnEventoGuardar(sender, e);
        }

        private void TsbCancelar_Click(object sender, EventArgs e)
        {
            OnEventoCancelar(sender, e);
        }

        private void TsbImprimir_Click(object sender, EventArgs e)
        {
            OnEventoImprimir(sender, e);
        }

        #endregion

        #region Funciones

        public void LoadPermisos()
        {
            VisibleNuevo = false;
            VisibleEditar = false;
            VisibleEliminar = false;
            VisibleGuardar = false;
            VisibleCancelar = false;

            try
            {
                UsuarioCn usuarioCn = new UsuarioCn();
                List<Permisos> permisos = usuarioCn.ObtenerPermisosPorUsuarioAndFormulario(DatosGenerales.PersonalActual.personalID,this.FormularioID);

                foreach (Permisos p in permisos)
                {
                    TipoAcceso acceso = (TipoAcceso)Enum.Parse(typeof(TipoAcceso), p.tipoPermiso.ToString());
                    switch (acceso)
                    {
                        case TipoAcceso.Mostrar:
                            break;
                        case TipoAcceso.Crear:
                            VisibleNuevo = p.estado;
                            break;
                        case TipoAcceso.Editar:
                            VisibleEditar = p.estado;
                            break;
                        case TipoAcceso.Eliminar:
                            VisibleEliminar = p.estado;
                            break;
                        default:
                            break;
                    }
                    if (p.estado)
                    {
                        VisibleGuardar = true;
                        VisibleCancelar = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #endregion
    }
}
